/**
 * 
 */
package org.statewalker.tokenizer.stream;

public interface ICharStream {

    public interface IMarker {

        void close(boolean reset);

        Pointer getPointer();

        String getSubstring(int len);

    }

    public static class Pointer implements Comparable<Pointer> {

        public static final Pointer START = new Pointer(0, 0, 0);

        public final int column;

        public final int line;

        public final int pos;

        public Pointer(int pos, int line, int linePos) {
            this.pos = pos;
            this.line = line;
            this.column = linePos;
        }

        public int compareTo(Pointer o) {
            int result = pos - o.pos;
            if (result != 0)
                return result;
            result = line - o.line;
            if (result != 0)
                return result;
            result = column - o.column;
            if (result != 0)
                return result;
            return 0;
        }

        @Override
        public boolean equals(Object obj) {
            if (this == obj)
                return true;
            if (!(obj instanceof Pointer))
                return false;
            Pointer p = (Pointer) obj;
            return pos == p.pos;
            // return pos == p.pos && line == p.line && column == p.column;
        }

        @Override
        public int hashCode() {
            return pos;
        }

        public Pointer inc(boolean newLine) {
            int l = newLine ? line + 1 : line;
            int c = newLine ? 0 : column + 1;
            return new Pointer(pos + 1, l, c);
        }

        public int len(Pointer pointer) {
            return pos - pointer.pos;
        }

        @Override
        public String toString() {
            return pos + "[" + line + ":" + column + "]";
        }

    }

    char getChar();

    Pointer getPointer();

    boolean incPos();

    IMarker markPosition();

}